package com.learn.hutool.json.model;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author XuYang
 * @since 2025/2/19 12:18
 */
@AllArgsConstructor(staticName = "of")
@NoArgsConstructor
@Data
public class JsonEntityExt {
    private Long id;
    private Ext ext;
    private JSONObject ext2;

    @Data
    public static class Ext
        implements cn.hutool.json.JSONBeanParser<Object>
    {
        private Long id;
        private String name;

        @Override
        public void parse(Object value) {
            JSONObject content;
            if (value instanceof String) {
                content = JSONUtil.parseObj(value);
            } else {
                content = (JSONObject) value;
            }
            BeanUtil.copyProperties(content, this);
        }
    }
}
